package com.shenmazong.serverwebpoem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shenmazong.serverwebpoem.mapper.ITbStoryMapper;
import com.shenmazong.serverwebpoem.pojo.TbStory;
import com.shenmazong.serverwebpoem.service.TbStoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 田不平
 * @project server-web-poem
 * @date 2020/3/23 8:51 PM
 * http://www.shenmazong.com
 */

@Service
public class TbStoryServiceImpl implements TbStoryService {

    @Autowired
    ITbStoryMapper iTbStoryMapper;

    @Override
    public void add(TbStory story) {
        iTbStoryMapper.insert(story);
    }

    @Override
    public void del(Integer id) {
        iTbStoryMapper.deleteById(id);
    }

    @Override
    public void set(TbStory story) {
        iTbStoryMapper.updateById(story);
    }

    @Override
    public TbStory getById(Integer id) {
        return iTbStoryMapper.selectById(id);
    }

    @Override
    public List<TbStory> getByPoetryId(Integer id) {

        Map<String,Object> columnMap = new HashMap<>();
        columnMap.put("poetryid", id);
        List<TbStory> stories = iTbStoryMapper.selectByMap(columnMap);

        return stories;
    }

    @Override
    public IPage<TbStory> getNoteByPage(Integer pageCurrent, Integer pageSize) {
        QueryWrapper<TbStory> queryWrapper = new QueryWrapper<>();
        //queryWrapper.eq("authorid", authorId);
        queryWrapper.orderByAsc("verify");
        queryWrapper.orderByDesc("id");

        Page<TbStory> page = new Page<>(pageCurrent, pageSize);
        IPage<TbStory> iPage = iTbStoryMapper.selectPage(page, queryWrapper);
        System.out.println("总页数:"+iPage.getPages());
        System.out.println("总记录数:"+iPage.getTotal());

        return iPage;
    }
}
